package com.ruoyi.resume.task;

import com.ruoyi.resume.service.TaskProcessorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ScheduledTaskRunner {

    @Autowired
    private TaskQueue taskQueue;

    @Autowired
    private TaskProcessorService taskProcessorService;

    @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨两点
    public void runScheduledTasks() {
        try {
            // 将整个任务队列交由 TaskProcessorService 处理
            taskProcessorService.processAllTasks(taskQueue);
            System.out.println("定时任务已执行完成");
        } catch (Exception e) {
            System.err.println("定时任务执行失败：" + e.getMessage());
        }
    }
}
